#ifndef FGE_SPRITEANIMATION_HPP
#define FGE_SPRITEANIMATION_HPP

#include <vector>

#include "Animation.hpp"
#include "TextureDictionary.hpp"

namespace fge
{

class AssetManager;

class SpriteAnimation
{
public:
	SpriteAnimation(const std::string &filename, AssetManager *assetManager);
	~SpriteAnimation();

	static SpriteAnimation* FromFile(const std::string &filename);

	std::vector<std::pair<TextureRegion, Texture*> > frames;

	float frameSeconds;
	bool loop;

protected:
	SpriteAnimation() : textureOwner(false) { }

	bool textureOwner;
};

class SpriteAnimationPlayer : public AnimationPlayer
{
public:
	SpriteAnimationPlayer();
	~SpriteAnimationPlayer();

	void AddAnimation(const std::string &name, SpriteAnimation *spriteAnimation);

	void StartAnimation(const std::string &name, bool allowRestart = false);

	AnimationEvent Update(float deltaSeconds);
	AnimationEvent SetTime(float seconds);

	void Draw(SpriteBatch *spriteBatch, const Vector2 &position, float rotation = 0, const Vector2 &scale = Vector2::ONE, const Color &tintColor = Color::White, bool flipHorizontal = false, bool flipVertical = false);

protected:
	std::map<std::string, SpriteAnimation*> animations;

	SpriteAnimation *currentAnimation;
	float currentAnimationTime;
	int currentFrame;
};

}

#endif//FGE_SPRITEANIMATION_HPP
